import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import('../views/Home.vue')
  },
  {
    path: '/login',
    name: "Login",
    component: () => import('../views/Login.vue')
  },
  {
    path: '/about',
    name: "About",
    component: () => import('../views/About'),
  },
  {
    path: '/bridal',
    name: "Bridal",
    component: () => import('../views/Bridal')
  },
  {
    path: '/rental',
    name: "Rental",
    component: () => import('../views/Rental')
  },
  {
    path: '/resold',
    name: "Resold",
    component: () => import('../views/Resold')
  },
  {
    path: '/ask_buy',
    name: "Ask_Buy",
    component: () => import('../views/Ask_Buy')
  },
  {
    path: '/demand_rent',
    name: "Demand_Rent",
    component: () => import('../views/Demand_rent')
  },
  {
    path: '/group_purchase',
    name: "Group_Purchase",
    component: () => import('../views/Group_Purchase')
  },
  {
    path: '/housing_ring',
    name: "Housing_Ring",
    component: () => import('../views/Housing_Ring')
  },
  {
    path: '/live_streaming',
    name: "Live_Streaming",
    component: () => import('../views/Live_Streaming')
  },
  {
    path: '/ranking_list',
    name: "Ranking_List",
    component: () => import('../views/Ranking_List')
  },
  {
    path: '/news',
    name: "News",
    component: () => import('../views/News')
  },
  {
    path: '/record',
    name: "Record",
    component: () => import('../views/Record')
  },
  {
    path: '/map',
    name: "Map",
    component: () => import('../views/Map')
  },
  {
    path: '/detail/:id',
    name: "Detail",
    component: () => import('../views/Detail')
  },
  {
    path: '/book',
    name: "Book",
    component: () => import('../views/Book')
  },
  {
    path: '/watch',
    name: "Watch",
    component: () => import('../views/Watch')
  },
  {
    path: '/pay/:id',
    name: "Pay",
    component: () => import('../views/Pay')
  },
  {
    path: '/quiz',
    name: "Quiz",
    component: () => import('../views/Quiz')
  },
  {
    path: '/broker/:id',
    name: "Broker",
    component: () => import('../views/Broker')
  },
  {
    path: '/starting/:id',
    name: "Starting",
    component: () => import('../views/Starting')
  },
  {
    path: '/anchor',
    name: "Anchor",
    component: () => import('../views/Anchor')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path !== '/login' && !localStorage.token) {
    return next('/login')
  }
  next()
})

export default router
